package com.css.zfzx.sjcj.modules.fxpc.fxCasEMap.service.impl;

import com.css.zfzx.sjcj.common.MenuInfoEnum;
import com.css.zfzx.sjcj.common.division.service.MyDivisionService;
import com.css.zfzx.sjcj.common.utils.StrUtils;
import com.css.zfzx.sjcj.modules.fxpc.fxCasEMap.repository.FxCasEMapNativeRepository;
import com.css.zfzx.sjcj.modules.fxpc.fxCaslMap.repository.FxCaslMapNativeRepository;
import com.css.zfzx.sjcj.modules.pojo.DivisionData;
import com.css.zfzx.sjcj.modules.pojo.QueryVo;
import com.css.zfzx.sjcj.modules.pojo.RequestParams;
import com.css.zfzx.sjcj.modules.pojo.RespondParams;
import com.css.zfzx.sjcj.modules.service.CommonInterfaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service("fxCasEMap1ServiceImpl")
public class FxCasEMap1ServiceImpl implements CommonInterfaceService {
    @Autowired
    private FxCasEMapNativeRepository nativeRepository;

    @Autowired
    private MyDivisionService myDivisionService;

    @Override
    public RespondParams dataStatistics(RequestParams params) {
        RespondParams respondParams = new RespondParams();

        List<String> menuIds = params.getMenuIds();
        MenuInfoEnum menuInfoEnum = MenuInfoEnum.FX_CASE_MAP_1;
        boolean isHave = StrUtils.splitMenuId(menuIds, menuInfoEnum);
        if (!isHave){
            return null;
        }
        List<DivisionData> divisionDatas = new ArrayList<>();
        List<String> divisions = params.getDivision();
        for (String division : divisions) {
            DivisionData divisionData = new DivisionData();
            QueryVo queryVo = myDivisionService.getDivisionName(division);
            divisionData.setDivision(queryVo.getDivisions());

            String collectionCount = "";
            String qualityCount = "";

            String startTime = params.getStartTime().toString();
            String endTime = params.getEndTime().toString();
            queryVo.setStartTime(startTime);
            queryVo.setEndTime(endTime);
            queryVo.setIdentify(3);
            collectionCount = nativeRepository.count(queryVo);
            divisionData.setCollectionCount(collectionCount);

            qualityCount = collectionCount;
            divisionData.setQualityCount(qualityCount);
            divisionDatas.add(divisionData);
        }
        respondParams.setDivisionDataList(divisionDatas);
        respondParams.setMenuId(menuInfoEnum.getMenuId());
        return respondParams;
    }
}
